package main;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class TaskReader {
	private BufferedReader reader;

	public TaskReader() {
	}

	/**
	 * 打开任务文件
	 * @param taskFile
	 */
	public void open(String taskFile) {
		try {
			reader = new BufferedReader(new FileReader(taskFile));
		} catch(Exception e) {
			e.printStackTrace(System.err);
		}
	}

	/**
	 * 读取一个任务
	 * @return
	 */
	public String readTask() {
		String task = null;

		try {
			String line = reader.readLine();
			if(line == null) {
				task = null;
			} else {
				line = line.trim();
				while(line != null && (line.length()==0 || line.startsWith("//"))) {
					line = reader.readLine();
				}
				task = line;
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return task;
	}

	/**
	 * 关闭任务文件
	 */
	public void close() {
		try {
			reader.close();
		} catch (IOException e) {
			e.printStackTrace(System.err);
		}
	}
}
